﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;
using System8ToyMC;
using System.IO.IsolatedStorage;

namespace t_System8ToyMCControls
{
    [TestClass]
    public class t_DataLoadSaveHelper
    {
        [TestInitialize]
        public void TestSetup()
        {
            var iso = IsolatedStorageFile.GetUserStoreForApplication();
            foreach (var d in iso.GetDirectoryNames())
            {
                foreach (var f in iso.GetFileNames(d + "\\*"))
                {
                    iso.DeleteFile(d + "\\" + f);
                }
                iso.DeleteDirectory(d);
            }
        }

        [TestMethod]
        public void TestCtor()
        {
            DataLoadSaveHelper h = new DataLoadSaveHelper();
            Assert.IsNotNull(h.LocalDatasets, "dataset not created");
            Assert.AreEqual(0, h.LocalDatasets.Count, "should be no datasets");
        }

        [TestMethod]
        public void TestSimpleSaveLoad()
        {
            DataLoadSaveHelper h = new DataLoadSaveHelper();
            System8Equations.S8Equations eqns = new System8Equations.S8Equations();
            h.SaveCurrentState("test", eqns);
            Assert.AreEqual(1, h.LocalDatasets.Count, "Expected one saved guy!");
            h.LoadCurrentState("test", eqns);
        }

        [TestMethod]
        public void TestLoad()
        {
            DataLoadSaveHelper h = new DataLoadSaveHelper();
            System8Equations.S8Equations eqns = new System8Equations.S8Equations();
            eqns.n.Total = 497008;
            eqns.p.Total = 26790;
            eqns.n1.Total = 60463;
            eqns.n2.Total = 213012;
            eqns.p1.Total = 7159;
            eqns.p2.Total = 16886;
            eqns.n12.Total = 36807;
            eqns.p12.Total = 5130;

            h.SaveCurrentState("test", eqns);

            System8Equations.S8Equations eqns1 = new System8Equations.S8Equations();
            h.LoadCurrentState("test", eqns1);

            Assert.AreEqual(eqns.n.Total, eqns1.n.Total, "n is not restored correctly");
            Assert.AreEqual(eqns.p.Total, eqns1.p.Total, "n is not restored correctly");
            Assert.AreEqual(eqns.n1.Total, eqns1.n1.Total, "n is not restored correctly");
            Assert.AreEqual(eqns.n2.Total, eqns1.n2.Total, "n is not restored correctly");
            Assert.AreEqual(eqns.p1.Total, eqns1.p1.Total, "n is not restored correctly");
            Assert.AreEqual(eqns.p2.Total, eqns1.p2.Total, "n is not restored correctly");
            Assert.AreEqual(eqns.p12.Total, eqns1.p12.Total, "n is not restored correctly");
            Assert.AreEqual(eqns.n12.Total, eqns1.n12.Total, "n is not restored correctly");
        }

        [TestMethod]
        public void TestAlreadySaved()
        {
            DataLoadSaveHelper h = new DataLoadSaveHelper();
            System8Equations.S8Equations eqns = new System8Equations.S8Equations();
            h.SaveCurrentState("test", eqns);

            DataLoadSaveHelper h1 = new DataLoadSaveHelper();
            Assert.AreEqual(1, h1.LocalDatasets.Count, "Expected there to be one already in storage!");
        }

        [TestMethod]
        public void TestActualNumbers()
        {
            DataLoadSaveHelper h = new DataLoadSaveHelper();
            System8Equations.S8Equations eqns = new System8Equations.S8Equations();
        }
    }
}